package org.shs.collector.dao;

import static org.shs.common.config.SystemInitializer.sqlHandler;

import java.util.ArrayList;

import org.shs.collector.form.CollectorForm;
import org.shs.collector.model.CollectorModel;
import org.shs.common.utils.DataHolder;

/**
 * Implementation of Database related operations for the Collector module. This
 * implementation fetches the data from a MySQL backend.
 * <br/>
 * <br/><b>Created:</b>&nbsp;&nbsp; Dec 23, 2008 1:54:34 AM
 *
 * @author Gunjan
 */
public class CollectorDAOImpl implements ICollectorDAO
{

   
   /* (non-Javadoc)
    * @see org.shs.collector.dao.ICollectorDAO#getCollectors(
    *    org.shs.common.utils.DataHolder)
    */
   @SuppressWarnings("unchecked")
   public ArrayList<CollectorModel> getCollectors(DataHolder collectorData)
            throws Exception
   {
      return (ArrayList<CollectorModel>)sqlHandler.queryForList(
                                       "Collector.getCollectors", collectorData);
   }
   
   /* (non-Javadoc)
    * @see org.shs.collector.dao.ICollectorDAO#delCollectorData(java.lang.String)
    */
   public void delCollectorData(String collectorId) throws Exception
   {
      // delete details for a collector
      sqlHandler.delete("Collector.delCollectorData", collectorId);
   }

   /* (non-Javadoc)
    * @see org.shs.collector.dao.ICollectorDAO#getCollectorDetails(java.lang.String)
    */
   public CollectorModel getCollectorDetails(String collectorId)
            throws Exception
   {
      return (CollectorModel) sqlHandler.queryForObject(
                                 "Collector.getCollectorDetails", collectorId);
   }

   /* (non-Javadoc)
    * @see org.shs.collector.dao.ICollectorDAO#addCollectorData(
    *    org.shs.collector.form.CollectorForm)
    */
   public String addCollectorData(CollectorForm collectorData)
            throws Exception
   {
      return (String) sqlHandler.insert("Collector.addCollectorData", collectorData);
   }

   /* (non-Javadoc)
    * @see org.shs.collector.dao.ICollectorDAO#editCollectorData(
    *    org.shs.collector.form.CollectorForm)
    */
   public void editCollectorData(CollectorForm collectorData) throws Exception
   {
      sqlHandler.update("Collector.editCollectorData", collectorData);
   }

   /* (non-Javadoc)
    * @see org.shs.collector.dao.ICollectorDAO#updActiveStatus(
    *    org.shs.common.utils.DataHolder)
    */
   public void updActiveStatus(DataHolder collectorActvData) throws Exception
   {
      sqlHandler.update("Collector.updCollectorActiveStatus", collectorActvData);
   }

}